﻿using SalaryChannel.Testwcf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SalaryChannel
{
    public partial class Test : UserControl
    {
        private TestServiceClient service;
        public Test()
        {
            InitializeComponent();
            service = new TestServiceClient();
            service.GetChannelByIdCompleted += service_GetChannelByIdCompleted;
        }

        /// <summary>
        /// wcf 处理结果回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void service_GetChannelByIdCompleted(object sender, GetChannelByIdCompletedEventArgs e)
        {
            datagrid1.ItemsSource = e.Result;
        }

        internal void Initiallize()
        {
            tb1.Text = string.Empty;
            datagrid1.ItemsSource = null;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int id = -1;

            if (!int.TryParse(tb1.Text, out id))
            {
                App.MessageBox.ShowDialog("请输入整数ID");
                return;
            }
            service.GetChannelByIdAsync(id);
        }
    }
}
